package com.gxjc.dao.bean;

import java.util.List;

import org.hibernate.Session;
import org.hibernate.Transaction;

import com.gxjc.model.Nature;

public class NatureDao extends BaseDao {
	public List<Nature> getAll() {
		String hql = "FROM Nature";
		return getSession().createQuery(hql).list();
	}

	public void save(Nature nature) {
		//Session session = getSession();
		//Transaction tx = session.beginTransaction();
		//tx.begin();
		getSession().save(nature);
		//tx.commit();
		//session.close();
	}

	public void update(Nature nature) {
		Session session = getSession();
		session.update(nature);
		session.getTransaction().commit();
		session.close();
	}
	
	public void delete(int id) {
		getSession().delete(getSession().get(Nature.class,id));
	}
	
	public Nature getNatureById(int id) {
		return (Nature)getSession().get(Nature.class,id);
	}
	
	public List<Nature> getNatureBySql(String hql) {
		return getSession().createQuery(hql).list();
	}
}
